package com.huawei.secure.android.common.detect.a;

import android.text.TextUtils;
import android.util.Log;
import java.lang.reflect.InvocationTargetException;

public class c {
    private static final String TAG = "ReflectUtil";

    public static Object a(String str, String str2, Class<?>[] clsArr, Object[] objArr) throws Exception {
        Class cls = Class.forName(str);
        return a(cls, cls.newInstance(), str2, clsArr, objArr);
    }

    public static String e(String str) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        String str2;
        try {
            Object a = a("android.os.SystemProperties", "get", new Class[]{String.class}, new Object[]{str});
            if (a instanceof String) {
                str2 = (String) a;
                return str2;
            }
        } catch (Exception e) {
            Log.e(TAG, "getSystemProperties, Excetion." + e.getMessage());
        }
        str2 = null;
        return str2;
    }

    private static Object a(Class<?> cls, Object obj, String str, Class<?>[] clsArr, Object[] objArr) throws Exception {
        a((Class) cls, (Class[]) clsArr, objArr);
        try {
            try {
                return cls.getMethod(str, clsArr).invoke(obj, objArr);
            } catch (IllegalAccessException e) {
                Log.e(TAG, "IllegalAccessException" + e.getMessage());
                return null;
            } catch (IllegalArgumentException e2) {
                Log.e(TAG, "IllegalArgumentException" + e2.getMessage());
                return null;
            } catch (InvocationTargetException e3) {
                Log.e(TAG, "InvocationTargetException" + e3.getMessage());
                return null;
            }
        } catch (NoSuchMethodException e4) {
            Log.e(TAG, "NoSuchMethodException" + e4.getMessage());
        }
    }

    private static void a(Class cls, Class[] clsArr, Object[] objArr) throws Exception {
        if (cls == null) {
            throw new Exception("class is null in staticFun");
        } else if (clsArr == null) {
            if (objArr != null) {
                throw new Exception("paramsType is null, but params is not null");
            }
        } else if (objArr == null) {
            throw new Exception("paramsType or params should be same");
        } else if (clsArr.length != objArr.length) {
            throw new Exception("paramsType len:" + clsArr.length + " should equal params.len:" + objArr.length);
        }
    }

    public static int a(Class<?> cls, String str, int i) {
        try {
            i = cls.getField(str).getInt(null);
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "IllegalArgumentException err:" + e.getMessage());
        } catch (IllegalAccessException e2) {
            Log.e(TAG, "IllegalAccessException err:" + e2.getMessage());
        } catch (NoSuchFieldException e3) {
            Log.e(TAG, "NoSuchFieldException err:" + e3.getMessage());
        }
        return i;
    }

    public static int a(String str, String str2, int i) {
        try {
            i = a(Class.forName(str), str2, i);
        } catch (Exception e) {
            Log.e(TAG, "getIntFiled exception" + e.getMessage());
        }
        return i;
    }

    public static Object a(Class<?> cls, String str, Object obj) {
        try {
            obj = cls.getField(str).get(null);
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "IllegalArgumentException" + e.getMessage());
        } catch (IllegalAccessException e2) {
            Log.e(TAG, "IllegalAccessException" + e2.getMessage());
        } catch (NoSuchFieldException e3) {
            Log.e(TAG, "NoSuchFieldException" + e3.getMessage());
        } catch (Exception e4) {
            Log.e(TAG, "Exception" + e4.getMessage());
        }
        return obj;
    }

    public static Object a(String str, String str2, Object obj) {
        try {
            obj = Class.forName(str).getField(str2).get(null);
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "IllegalArgumentException" + e.getMessage());
        } catch (IllegalAccessException e2) {
            Log.e(TAG, "IllegalAccessException" + e2.getMessage());
        } catch (NoSuchFieldException e3) {
            Log.e(TAG, "NoSuchMethodException" + e3.getMessage());
        } catch (ClassNotFoundException e4) {
            Log.e(TAG, "ClassNotFoundException" + e4.getMessage());
        } catch (Exception e5) {
            Log.e(TAG, "Exception" + e5.getMessage());
        }
        return obj;
    }

    public static Class f(String str) {
        try {
            return Class.forName(str);
        } catch (ClassNotFoundException e) {
            Log.e(TAG, "ClassNotFoundException" + e.getMessage());
            return null;
        } catch (Exception e2) {
            Log.e(TAG, "Exception" + e2.getMessage());
            return null;
        } catch (Throwable th) {
            Log.e(TAG, "Throwable" + th.getMessage());
            return null;
        }
    }
}
